package com.sandking.db.bean;

import com.sandking.tools.SK_Map;
import java.util.ArrayList;
import com.sandking.db.cache.BydlCache;
import com.sandking.db.cache.YhCache;
import com.alibaba.fastjson.JSON;
import java.util.Map;
import com.sandking.io.SK_OutputStream;
import java.util.List;
import com.sandking.io.SK_InputStream;
import com.sandking.db.cache.YhyxCache;
import java.io.ByteArrayInputStream;
import java.util.HashMap;
import java.io.ByteArrayOutputStream;

/**
 * 兵营队列
 */
public class Bydl {

	public static final String TABLENAME = "兵营队列";
	public static final String CLASSNAME = "Bydl"; 
	/**
	 * 需要更新字段集
	 */
	private Map<String, Object> updateColumns;

	/** id */
	private int id;
	
	/** tempid */
	private int tempid;
	
	/** 用户英雄_id */
	private int yhyx_id;
	
	/** 用户英雄tempid */
	private int yhyxtempid;
	
	/** 用户_id */
	private int yh_id;
	
	/** 数量 */
	private int sl;
	
	/** 单位时间 */
	private int dwsj;
	
	/** 开始时间 */
	private java.util.Date kssj;
	
	/** 更新时间 */
	private java.util.Date gxsj;
	
	/** 结束时间 */
	private java.util.Date jssj;
	
	
	public Bydl() {
		super();
	}
	
	public Bydl(int id, int tempid, int yhyx_id, int yhyxtempid, int yh_id, int sl, int dwsj, java.util.Date kssj, java.util.Date gxsj, java.util.Date jssj) {
		super();
		this.id = id;
		this.tempid = tempid;
		this.yhyx_id = yhyx_id;
		this.yhyxtempid = yhyxtempid;
		this.yh_id = yh_id;
		this.sl = sl;
		this.dwsj = dwsj;
		this.kssj = kssj;
		this.gxsj = gxsj;
		this.jssj = jssj;
	}
	
	public Map<String, Object> getUpdateColumns() {
		if(updateColumns == null)
			updateColumns = new HashMap<String, Object>();
		return updateColumns;
	}
	
	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id = id;
		addUpdateColumn("id",id);
	}
	
	public void changeIdWith(int id){
		this.id += id;
		setId(this.id);
	}
	
	public void changeIdWithMin(int id,int min){
		this.id += id;
		this.id = this.id < min ? min : this.id;
		setId(this.id);
	}
	
	public void changeIdWithMax(int id,int max){
		this.id += id;
		this.id = this.id > max ? max : this.id;
		setId(this.id);
	}
	
	public void changeIdWithMaxMin(int id,int max,int min){
		this.id += id;
		this.id = this.id < min ? min : this.id;
		this.id = this.id > max ? max : this.id;
		setId(this.id);
	}	
	public int getTempid() {
		return tempid;
	}
	
	public void setTempid(int tempid) {
		this.tempid = tempid;
		addUpdateColumn("tempid",tempid);
	}
	
	public void changeTempidWith(int tempid){
		this.tempid += tempid;
		setTempid(this.tempid);
	}
	
	public void changeTempidWithMin(int tempid,int min){
		this.tempid += tempid;
		this.tempid = this.tempid < min ? min : this.tempid;
		setTempid(this.tempid);
	}
	
	public void changeTempidWithMax(int tempid,int max){
		this.tempid += tempid;
		this.tempid = this.tempid > max ? max : this.tempid;
		setTempid(this.tempid);
	}
	
	public void changeTempidWithMaxMin(int tempid,int max,int min){
		this.tempid += tempid;
		this.tempid = this.tempid < min ? min : this.tempid;
		this.tempid = this.tempid > max ? max : this.tempid;
		setTempid(this.tempid);
	}	
	public int getYhyx_id() {
		return yhyx_id;
	}
	
	public void setYhyx_id(int yhyx_id) {
		this.yhyx_id = yhyx_id;
		addUpdateColumn("用户英雄_id",yhyx_id);
	}
	
	public void changeYhyx_idWith(int yhyx_id){
		this.yhyx_id += yhyx_id;
		setYhyx_id(this.yhyx_id);
	}
	
	public void changeYhyx_idWithMin(int yhyx_id,int min){
		this.yhyx_id += yhyx_id;
		this.yhyx_id = this.yhyx_id < min ? min : this.yhyx_id;
		setYhyx_id(this.yhyx_id);
	}
	
	public void changeYhyx_idWithMax(int yhyx_id,int max){
		this.yhyx_id += yhyx_id;
		this.yhyx_id = this.yhyx_id > max ? max : this.yhyx_id;
		setYhyx_id(this.yhyx_id);
	}
	
	public void changeYhyx_idWithMaxMin(int yhyx_id,int max,int min){
		this.yhyx_id += yhyx_id;
		this.yhyx_id = this.yhyx_id < min ? min : this.yhyx_id;
		this.yhyx_id = this.yhyx_id > max ? max : this.yhyx_id;
		setYhyx_id(this.yhyx_id);
	}	
	public int getYhyxtempid() {
		return yhyxtempid;
	}
	
	public void setYhyxtempid(int yhyxtempid) {
		this.yhyxtempid = yhyxtempid;
		addUpdateColumn("用户英雄tempid",yhyxtempid);
	}
	
	public void changeYhyxtempidWith(int yhyxtempid){
		this.yhyxtempid += yhyxtempid;
		setYhyxtempid(this.yhyxtempid);
	}
	
	public void changeYhyxtempidWithMin(int yhyxtempid,int min){
		this.yhyxtempid += yhyxtempid;
		this.yhyxtempid = this.yhyxtempid < min ? min : this.yhyxtempid;
		setYhyxtempid(this.yhyxtempid);
	}
	
	public void changeYhyxtempidWithMax(int yhyxtempid,int max){
		this.yhyxtempid += yhyxtempid;
		this.yhyxtempid = this.yhyxtempid > max ? max : this.yhyxtempid;
		setYhyxtempid(this.yhyxtempid);
	}
	
	public void changeYhyxtempidWithMaxMin(int yhyxtempid,int max,int min){
		this.yhyxtempid += yhyxtempid;
		this.yhyxtempid = this.yhyxtempid < min ? min : this.yhyxtempid;
		this.yhyxtempid = this.yhyxtempid > max ? max : this.yhyxtempid;
		setYhyxtempid(this.yhyxtempid);
	}	
	public int getYh_id() {
		return yh_id;
	}
	
	public void setYh_id(int yh_id) {
		this.yh_id = yh_id;
		addUpdateColumn("用户_id",yh_id);
	}
	
	public void changeYh_idWith(int yh_id){
		this.yh_id += yh_id;
		setYh_id(this.yh_id);
	}
	
	public void changeYh_idWithMin(int yh_id,int min){
		this.yh_id += yh_id;
		this.yh_id = this.yh_id < min ? min : this.yh_id;
		setYh_id(this.yh_id);
	}
	
	public void changeYh_idWithMax(int yh_id,int max){
		this.yh_id += yh_id;
		this.yh_id = this.yh_id > max ? max : this.yh_id;
		setYh_id(this.yh_id);
	}
	
	public void changeYh_idWithMaxMin(int yh_id,int max,int min){
		this.yh_id += yh_id;
		this.yh_id = this.yh_id < min ? min : this.yh_id;
		this.yh_id = this.yh_id > max ? max : this.yh_id;
		setYh_id(this.yh_id);
	}	
	public int getSl() {
		return sl;
	}
	
	public void setSl(int sl) {
		this.sl = sl;
		addUpdateColumn("数量",sl);
	}
	
	public void changeSlWith(int sl){
		this.sl += sl;
		setSl(this.sl);
	}
	
	public void changeSlWithMin(int sl,int min){
		this.sl += sl;
		this.sl = this.sl < min ? min : this.sl;
		setSl(this.sl);
	}
	
	public void changeSlWithMax(int sl,int max){
		this.sl += sl;
		this.sl = this.sl > max ? max : this.sl;
		setSl(this.sl);
	}
	
	public void changeSlWithMaxMin(int sl,int max,int min){
		this.sl += sl;
		this.sl = this.sl < min ? min : this.sl;
		this.sl = this.sl > max ? max : this.sl;
		setSl(this.sl);
	}	
	public int getDwsj() {
		return dwsj;
	}
	
	public void setDwsj(int dwsj) {
		this.dwsj = dwsj;
		addUpdateColumn("单位时间",dwsj);
	}
	
	public void changeDwsjWith(int dwsj){
		this.dwsj += dwsj;
		setDwsj(this.dwsj);
	}
	
	public void changeDwsjWithMin(int dwsj,int min){
		this.dwsj += dwsj;
		this.dwsj = this.dwsj < min ? min : this.dwsj;
		setDwsj(this.dwsj);
	}
	
	public void changeDwsjWithMax(int dwsj,int max){
		this.dwsj += dwsj;
		this.dwsj = this.dwsj > max ? max : this.dwsj;
		setDwsj(this.dwsj);
	}
	
	public void changeDwsjWithMaxMin(int dwsj,int max,int min){
		this.dwsj += dwsj;
		this.dwsj = this.dwsj < min ? min : this.dwsj;
		this.dwsj = this.dwsj > max ? max : this.dwsj;
		setDwsj(this.dwsj);
	}	
	public java.util.Date getKssj() {
		return kssj;
	}
	
	public void setKssj(java.util.Date kssj) {
		this.kssj = kssj;
		addUpdateColumn("开始时间",kssj);
	}
	
	public java.util.Date getGxsj() {
		return gxsj;
	}
	
	public void setGxsj(java.util.Date gxsj) {
		this.gxsj = gxsj;
		addUpdateColumn("更新时间",gxsj);
	}
	
	public java.util.Date getJssj() {
		return jssj;
	}
	
	public void setJssj(java.util.Date jssj) {
		this.jssj = jssj;
		addUpdateColumn("结束时间",jssj);
	}
	
	
	//用户_id
	public Yh getYhPkYh_id(){
		return YhCache.getById(yh_id);
	}
	//用户英雄_id
	public Yhyx getYhyxPkYhyx_id(){
		return YhyxCache.getById(yhyx_id);
	}
	public void addUpdateColumn(String key, Object val) {
		Map<String, Object> map = getUpdateColumns();
		if (map == null)
			return;
		map.put(key, val);
	}
	
	public void clearUpdateColumn() {
		Map<String, Object> map = getUpdateColumns();
		if (map == null)
			return;
		map.clear();
	}
	
	public Map<String, Object> toMap(){
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("id", this.id);
        result.put("tempid", this.tempid);
        result.put("yhyx_id", this.yhyx_id);
        result.put("yhyxtempid", this.yhyxtempid);
        result.put("yh_id", this.yh_id);
        result.put("sl", this.sl);
        result.put("dwsj", this.dwsj);
        result.put("kssj", this.kssj);
        result.put("gxsj", this.gxsj);
        result.put("jssj", this.jssj);
        return result;
    }
    
    public String toString(){
        return toMap().toString();
    }
    
    public String toJson(){
    	return JSON.toJSONString(toMap());
    }
    
    /**
     * 数据库源字段Map
     */
    public Map<String, Object> toColumnNameMap(){
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("id", this.id);
        result.put("tempid", this.tempid);
        result.put("用户英雄_id", this.yhyx_id);
        result.put("用户英雄tempid", this.yhyxtempid);
        result.put("用户_id", this.yh_id);
        result.put("数量", this.sl);
        result.put("单位时间", this.dwsj);
        result.put("开始时间", this.kssj);
        result.put("更新时间", this.gxsj);
        result.put("结束时间", this.jssj);
        return result;
    }
    
    public String toColumnNameString(){
        return toColumnNameMap().toString();
    }
    
    public byte[] toBytes() throws Exception {
    	try (ByteArrayOutputStream out = new ByteArrayOutputStream();) {
		    SK_OutputStream.writeInt(out,this.id);
		    SK_OutputStream.writeInt(out,this.tempid);
		    SK_OutputStream.writeInt(out,this.yhyx_id);
		    SK_OutputStream.writeInt(out,this.yhyxtempid);
		    SK_OutputStream.writeInt(out,this.yh_id);
		    SK_OutputStream.writeInt(out,this.sl);
		    SK_OutputStream.writeInt(out,this.dwsj);
		    return out.toByteArray();
    	}catch (Exception e) {
            throw e;
        }
    }
    
     public static Bydl createForBytes(byte[] _byte) throws Exception {
     	try (ByteArrayInputStream in = new ByteArrayInputStream(_byte);) {
	     	Bydl bydl = new Bydl();
		    bydl.id = SK_InputStream.readInt(in,null);
		    bydl.tempid = SK_InputStream.readInt(in,null);
		    bydl.yhyx_id = SK_InputStream.readInt(in,null);
		    bydl.yhyxtempid = SK_InputStream.readInt(in,null);
		    bydl.yh_id = SK_InputStream.readInt(in,null);
		    bydl.sl = SK_InputStream.readInt(in,null);
		    bydl.dwsj = SK_InputStream.readInt(in,null);
		    return bydl;
    	}catch (Exception e) {
            throw e;
        }
     }
    
    /**
     * 根据list创建对象
     */
    public static List<Bydl> createForColumnNameList(List<Map<String, Object>> list){
    	List<Bydl> bydls = new ArrayList<Bydl>();
		for (Map<String, Object> map : list) {
			bydls.add(createForColumnNameMap(map));
		}
		return bydls;
    }
    
    /**
     * 根据map创建对象
     */
    public static Bydl createForColumnNameMap(Map<String, Object> map){
    	Bydl obj = new Bydl();
	    obj.id = SK_Map.getInt("id", map);
	    obj.tempid = SK_Map.getInt("tempid", map);
	    obj.yhyx_id = SK_Map.getInt("用户英雄_id", map);
	    obj.yhyxtempid = SK_Map.getInt("用户英雄tempid", map);
	    obj.yh_id = SK_Map.getInt("用户_id", map);
	    obj.sl = SK_Map.getInt("数量", map);
	    obj.dwsj = SK_Map.getInt("单位时间", map);
        return obj;
    }
    
    /**
     * 根据list创建对象
     */
    public static List<Bydl> createForList(List<Map<String, Object>> list){
    	List<Bydl> bydls = new ArrayList<Bydl>();
		for (Map<String, Object> map : list) {
			bydls.add(createForColumnNameMap(map));
		}
		return bydls;
    }
    
    /**
     * 根据map创建对象
     */
    public static Bydl createForMap(Map<String, Object> map){
    	Bydl obj = new Bydl();
	    obj.id = SK_Map.getInt("id", map);
	    obj.tempid = SK_Map.getInt("tempid", map);
	    obj.yhyx_id = SK_Map.getInt("yhyx_id", map);
	    obj.yhyxtempid = SK_Map.getInt("yhyxtempid", map);
	    obj.yh_id = SK_Map.getInt("yh_id", map);
	    obj.sl = SK_Map.getInt("sl", map);
	    obj.dwsj = SK_Map.getInt("dwsj", map);
        return obj;
    }
    
    public static Bydl createForJson(String json){
    	Map<String, Object> map = JSON.parseObject(json);
    	return createForMap(map);
    }
    
    public static List<Bydl> createForJson(List<String> jsons){
    	List<Bydl> bydls = new ArrayList<Bydl>();
    	for(String json : jsons){
    		bydls.add(createForJson(json));
    	}
    	return bydls;
    }
    
    /** 延迟插入数据库 */
    public Bydl insert(){
    	return BydlCache.insert(this);
    }
    /** 延迟更新数据库 */
    public Bydl update(){
    	return BydlCache.update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return BydlCache.delete(this);
    }
    /** 即时插入数据库 */
    public Bydl insertAndFlush(){
    	return BydlCache.insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public Bydl updateAndFlush(){
    	return BydlCache.updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return BydlCache.deleteAndFlush(this);
    }
}